<?php
namespace Home\Model;

use Think\Model;

class CompanyModel extends Model
{
   /* protected $_validate = array(
     //   array('company_name', 'require', '企业名称必填！', 1), array('desc', 'require', '企业描述必填！', 1),
        //array ('topic_lead','require','引导语必填！',1 ),
    );*/

    public function getInfoByUid($uid) {
        $info = $this->where(array('uid' => $uid))->find();
        if ($info) {
            $arr = array($info['province'], $info['city'], $info['country']);
            $info['place'] = D("Region")->getMessagePlace($arr);
        }


        return $info;
    }

    public function addBase($data) {
        if (!$this->create($data)) {
            return array("status" => 1, "msg" => $this->getError());
        }
        if ($this->hasCompany($data['uid']) == false) {
            $data['ctime'] = time();
           $bool = $this->add($data);
        }else{
            $bool=$this->where(array("uid"=>$data['uid']))->save($data);
        }
        if($bool){
            return array("status"=>1,"msg"=>"完善成功!");
        }else{
            return array("status"=>0,"msg"=>"完善失败!");
        }
    }

    public function hasCompany($uid) {
        return $this->where(array("uid" => $uid))->count();
    }
}